﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml.Serialization;

public partial class CurveData : Data
{
    public CurveData() { }
    public CurveData(MonoBehaviour mono) : base(mono)
    {
        bonesLength = new List<float>();
        circleScale = Vector3.one;
    }
    [XmlIgnore] public Transform[] bones;
    [XmlIgnore] public Hair pair;
    [XmlIgnore] public List<Hair> relaHairs;
    public List<string> relaHairsName;
    public Vector3 pivotEuler;
    public Vector3 circleScale;
    public float circleAngle;

    [XmlIgnore] public Curve3 pose { get { return curve; } }//just alias
    public Curve3 curve;
    public float step = 0.01f; //approach value Snap时的每次迭代增加的长度
    public List<float> bonesLength;

    public void GetLengths()
    {
        var list = new List<float>();
        int i = 1;
        for (; i < bones.Length; i++)
        {
            var dist = Vector3.Distance(bones[i - 1].position, bones[i].position);
            list.Add(dist);
        }
        // tail
        list.Add(Vector3.Distance(bones[i - 1].position, bones[i - 1].GetChild(0).position));
        bonesLength = list;
    }

    public CurveData Clone()
    {
        var n = (CurveData)MemberwiseClone();
        n.bones = bones.Copy();
        n.relaHairs = relaHairs.Copy();
        n.relaHairsName = relaHairsName.Copy();
        n.bonesLength = bonesLength.Copy();
        n.curve = curve.Clone();
        return n;
    }
}
